package com.rocketmq.example;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class E03_OneWayMessage {



    /**
     * 单向发送，不关心对方是都接到，是否发送成功，只关心自己是否发送完成
     */
    public static void main(String[] args) {
         DefaultMQProducer producer = new DefaultMQProducer(ExampleMQConfig.TOPIC.getName());
        producer.setNamesrvAddr(ExampleMQConfig.ENDPOINT.getName());
        try {
            producer.start();
        } catch (MQClientException e) {
            e.printStackTrace();
        }
        try {
            for (int i = 0; i < 10; i++) {
                Message message = new Message(ExampleMQConfig.TOPIC.getName(), ExampleMQConfig.TAG.getName(),
                        ("message:" + 1).getBytes(RemotingHelper.DEFAULT_CHARSET));
               producer.sendOneway(message);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            System.err.println("发完了");
            producer.shutdown();
        }
       
    }
    

}
